/**
 * 
 */
package com.circle.model.util;

import java.io.*;
import java.util.Properties;

/**
 * @author tianming.fan
 *
 */
public class ResourceUtil {

	private static Properties dbProp = null;

	private static Properties sysProp = null;


	public static Properties initSysProp() throws Exception {

		String proFilePath = System.getProperty("user.dir") + File.separator + "sysconfig.properties";
		// //System.out.println("proFilePath:"+proFilePath);
		sysProp = new Properties();

		// InputStream in =
		// Object.class.getResourceAsStream(proFilePath);//配置文件在jar包内则用这种形式
		InputStream in = new FileInputStream(proFilePath);// 配置文件在jar包外面则用这种形式
		sysProp.load(in);
		// //System.out.println(prop.getProperty("maxMemory").trim());

		return sysProp;
	}

	public static String getConfig(String key) throws Exception {

		if (null == dbProp) {
			sysProp = initSysProp();
		}

		String value = sysProp.getProperty(key).trim();

		return value;
	}

	public static String getDBConfig(String key){
		if (null == dbProp) {
			String proFilePath = System.getProperty("user.dir") + File.separator + "dbconfig.properties";
			// //System.out.println("proFilePath:"+proFilePath);
			dbProp = new Properties();

			// InputStream in =
			// Object.class.getResourceAsStream(proFilePath);//配置文件在jar包内则用这种形式
			InputStream in;
			try {
				in = new FileInputStream(proFilePath);
				// 使用 InputStreamReader 指定编码为 UTF-8
				Reader reader = new InputStreamReader(in, "UTF-8");
				dbProp.load(reader);
			} catch (Exception e) {
				e.printStackTrace();
			}// 配置文件在jar包外面则用这种形式
			// //System.out.println(prop.getProperty("maxMemory").trim());
		}
		String value = dbProp.getProperty(key).trim();

		return value;
	}

}
